package logic

import (
	"context"
	"product/productrpc/productrpc"

	"product/api/internal/svc"
	"product/api/internal/types"

	"github.com/zeromicro/go-zero/core/logx"
)

type UpdatepasswordLogic struct {
	logx.Logger
	ctx    context.Context
	svcCtx *svc.ServiceContext
}

func NewUpdatepasswordLogic(ctx context.Context, svcCtx *svc.ServiceContext) *UpdatepasswordLogic {
	return &UpdatepasswordLogic{
		Logger: logx.WithContext(ctx),
		ctx:    ctx,
		svcCtx: svcCtx,
	}
}

func (l *UpdatepasswordLogic) Updatepassword(req *types.UpdatePasswordRequest) (resp *types.Response, err error) {
	// todo: add your logic here and delete this line
	update, err := l.svcCtx.ProductRpc.UdatePassword(l.ctx, &productrpc.UdatePasswordRequest{
		Account:     req.Account,
		Password:    req.Password,
		SendCode:    req.SendCode,
		Newpassword: req.NewPassword,
	})
	if err != nil {
		return &types.Response{
			Message: err.Error(),
			Code:    500,
			Data:    nil,
		}, nil
	}
	return &types.Response{
		Message: "修改密码成功",
		Code:    200,
		Data:    update,
	}, nil
}
